﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class MeetingSignIn : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MeetingSignInOutParam result = new MeetingSignInOutParam();
            MeetingSignInInParam param = new MeetingSignInInParam();
            string logMsg = "";
            bool isFlag = true;
            
            try
            {
                param = inParam as MeetingSignInInParam; 
                
                //SXT.Utility.Logs.WriteTxtFile(SerializeHelper.JsonSerializer<MeetingSignInInParam>(param), "Test");
                if (param.meeting_id.Length > 32)
                {
                    param.meeting_id = param.meeting_id.Remove(0,1);
                }
                //SXT.Utility.Logs.WriteTxtFile(SerializeHelper.JsonSerializer<MeetingSignInInParam>(param), "Test");
               
                if (string.IsNullOrEmpty(param.user_id) || string.IsNullOrEmpty(param.meeting_id))
                {
                    result.code = "0";
                    result.desc = "用户ID,会议ID/党课ID/活动ID不能为空";

                    isFlag = false;
                }

                if (CommonUtils.IsDisableUsers(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户状态有问题，请联系管理员";

                    isFlag = false;
                }
                if (isFlag)
                {
                    if (param.type != "1" && param.type != "2" && param.type != "3")
                    {
                        result.code = "0";
                        result.desc = "类型不能为空，且只能为1 会议;2 党课;3 支部活动";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    if (param.type == "1")
                    {
                        if (!InterfaceHelper.MeetingSignIn(param.user_id, param.meeting_id))
                        {
                            result.code = "0";
                            result.desc = "type=1,签到失败。";
                        }
                    }
                    else if (param.type == "2")
                        if (!InterfaceHelper.CoursesSignIn(param.user_id, param.meeting_id))
                        {
                            result.code = "0";
                            result.desc = "type=2,签到失败。";
                        }
                        else
                            if (!InterfaceHelper.RanchActivitieSignIn(param.user_id, param.meeting_id))
                            {
                                result.code = "0";
                                result.desc = "签到失败。";
                            }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-MeetingSignIn", SerializeHelper.JsonSerializer<MeetingSignInInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MeetingSignInInParam, MeetingSignInOutParam>();
            else
                SafeProcessRequest<MeetingSignInInParam, MeetingSignInOutParam>();
        }
    }

    #region 请求参数
    public class MeetingSignInInParam
    {
        /// <summary>
        /// 必填 用户ID
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        /// 必填	会议ID
        /// </summary>
        public string meeting_id
        { get; set; }

        /// <summary>
        /// 必填	类型 1 会议 2 党课 3 支部活动
        /// </summary>
        public string type
        { get; set; } 
    }
    #endregion

    #region 结果参数
    public class MeetingSignInOutParam
    {
        public MeetingSignInOutParam()
        {
            code = "1";
            desc = "操作成功"; 
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; } 
    }  
    #endregion 
}